<template>
	<!-- 我的车辆 -->
	<view class="content">
		<view class="cart-info">
			<u-swipe-action :show="show" @click="click(item.id)" @open="open" btn-width="100" :options="options"
				v-for="(item, index) in list" :key="item.id">
				<view class="item">
					<view class="title-wrap">
					<image src="../../static/login/logo@2x.png" mode=""></image>
					<view class="content-warp">
						<text>{{item.carNum}}</text>
						<text>登记日期:{{item.createTime}}</text>
						<text>累计停车时长:{{item.titles}}</text>
					</view>
				</view>
				</view>
				
			</u-swipe-action>
			<view class="addCar" @click="addCar">
				<u-icon name="plus" size="32"></u-icon>
				<text>添加车辆</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				show: false,
				disabled: false,
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d',
						height: '230rpx',
						background: '#FE6000',
						borderRadius: '16rpx',
						marginLeft: '16rpx',
						fontSize: '28rpx',
					}
				}]
			};
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList(pages) {
				// 获取openId
				let openId = uni.getStorageSync("userInfo").openid;
				let payload = {
					openid: openId
				};
				this.$Api.getUserCarList(payload).then((res) => {
					console.log(res)
					this.list = res.data.dataList;
				});
			},
			click(id) {
				let openId = uni.getStorageSync("userInfo").openid;
				let payload = {
					openid: openId,
					id:id,
					version:1
				};
				this.$Api.deleteCarInfo(payload).then((res) => {
					console.log(res)
					if(res.data.code==200){
						this.$u.toast('删除成功');
						this.getList()
					}
				});
			},
			// 如果打开一个的时候，不需要关闭其他，则无需实现本方法
			open(index) {
				this.show = true;
				this.list.map((val, idx) => {
					if (index != idx) this.show = false;
				})
			},
			addCar(){
				uni.navigateTo({
					url:"/pageB/myCar/addCar"
				})
			}
		}

	};
</script>

<style scoped lang="scss">
	@import "index.scss"
	
</style>